package com.ihy.utils;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

/**
 * hibernate连接工具类
 */
public class HibernateUtil {
    //sessionFactory
    private static final SessionFactory sessionFactory;

    static {
        //读取hibernate.cfg.xml文件
        Configuration configuration = new Configuration();
        Configuration configure = configuration.configure("/hibernate.cfg.xml");
        //构建sessionFactory
        sessionFactory = configure.buildSessionFactory();
    }

    //获取openSession
    public static Session getOpenSession() {
        return sessionFactory.openSession();
    }

    //获取currentSession
    public static Session getCurrentSession() {
        return sessionFactory.getCurrentSession();
    }
}
